<template>
  <div class="container">
    <div class="header">
      <div class="header-left-item">
        <div><img id="manager-avatar-img" :src="circleUrl" alt="" /></div>
        <div><h2>{{managerInfo.name}}</h2></div>
      </div>
      <div class="header-right-item">
        <el-button type="primary" round @click="toManagerEdit"
          >编 辑 资 料</el-button
        >
      </div>
    </div>
    <div class="my-content">
      <div class="my-content-line">
        <div class="key"><h3>个人基本信息</h3></div>
      </div>
      <div class="my-content-line">
        <div class="key">姓名：</div>
        <div class="value">{{ managerInfo.name }}</div>
      </div>
      <div class="my-content-line">
        <div class="key">性别：</div>
        <div class="value">
          <li v-if="managerInfo.gender == '男'" class="el-icon-male"></li>
          <li v-if="managerInfo.gender == '女'" class="el-icon-female"></li>
          {{ managerInfo.gender }}
        </div>
      </div>
      <div class="my-content-line">
        <div class="key">手机：</div>
        <div class="value">{{ managerInfo.phone }}</div>
      </div>
      <div class="my-content-line">
        <div class="key">学校：</div>
        <div class="value">{{ managerInfo.university }}</div>
      </div>
      <div class="my-content-line">
        <div class="key">邮箱：</div>
        <div class="value">{{ managerInfo.email }}</div>
      </div>
      <div class="my-content-line">
        <div class="key">管理员类型：</div>
        <div class="value">{{ managerInfo.type }}</div>
      </div>
      <div class="my-content-line">
        <div class="key">账号创建时间：</div>
        <div class="value">{{ managerInfo.createTime }}</div>
      </div>
    </div>
  </div>
</template>

<script>
import { downloadAvatar, getManagerInfo } from "@/api";
export default {
  data() {
    return {
      circleUrl:
        "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png", //默认头像
      managerInfo: {}, //管理员基本信息
    };
  },
  created() {
    this.downloadManagerAvatar();
    this.initManagerInfo();
  },
  methods: {
    //跳转到管理员个人信息编辑页面
    toManagerEdit() {
      this.$router.push({ name: "managerEdit" });
    },
    //下载用户头像
    async downloadManagerAvatar() {
      let params = {
        avatarUrl: this.$store.state.user.userInfo.avatarUrl,
      };
      let res = await downloadAvatar(params);
      let avatar_img = document.querySelector("#manager-avatar-img");
      let imageType = res.type; //获取图片类型
      const blob = new Blob([res], { type: imageType });
      const imageUrl = (window.URL || window.webkitURL).createObjectURL(blob);
      avatar_img.src = imageUrl;
      avatar_img.onload = function (e) {
        window.URL.revokeObjectURL(avatar_img.src); //释放URL.createObjectURL()创建的对象
      };
    },
    async initManagerInfo() {
      let res = await getManagerInfo();
      if (res.code !== 0) {
        this.$message.error("获取管理员基本信息失败");
        return;
      }
      this.managerInfo = res.data;
    },
  },
};
</script>

<style lang="less" scoped>
.container {
  padding: 10px;
  display: flex;
  flex-direction: column;
}
.header {
  border-radius: 10px 10px 0px 0px;
  display: flex;
  align-items: center;
  width: 70%;
  justify-content: space-between;
  background: rgb(255, 255, 255);
  border-bottom: 1px solid rgb(217, 212, 212);
  .header-left-item {
    padding: 20px;
    display: flex;
    flex-direction: row;
    align-items: center;
    div {
      margin: 5px;
    }
  }
  .header-right-item {
    padding: 10px;
  }
}
.my-content {
  padding-bottom: 20px;
  border-radius: 0px 0px 10px 10px;
  flex: 1;
  background: rgb(255, 255, 255);
  width: 70%;
  .my-content-line {
    display: flex;
    align-items: center;
    .key {
      width: 150px;
      text-align: right;
      padding: 10px;
    }
    .value {
      flex: 1;
      text-align: left;
      padding: 10px;
    }
  }
}

#manager-avatar-img {
  height: 90px;
  width: 90px;
  border-radius: 50px;
}
#university-logo {
  height: 50px;
  width: 50px;
  border-radius: 50px;
}
</style>